$(document).ready(function (){
    var courseId={};

   $("[name='changCourse']") .click(function (){
       $("#update-course").modal({
           backdrop:'static'
       });
       $("#courseName").val($(this).parent().prev().children().text());
       courseId=$(this).parent().prev().children().attr("courseId");
   });

   $("#saveCourseName").click(function (){
       var course={};
       course.courseId=courseId;
       course.cousrName=$("#courseName").val();
       course.cousrInfo=$("#courseInfo").val();
       course.major=$("#major").val();
       $.ajax({
           type:"POST",
           url:"/ssm/admin/course/saveCourse",
           contentType:"application/x-www-form-urlencoded; charset=utf-8",
           data:course,
           dataType:"json",
           success:function (result){
               if (result.msg=="名字已经存在")
               {
                   swal(result.msg);
               }
               else {
                   swal(result.msg);
                   $("button").click(function (){
                       location.reload();
                   });
               }
           },
           error:function (){
               alert("更新失败");
           }
       });
   	})
	$("[name='deleteCourse']").click(function (){
	    var course={};
	    course.courseId=$(this).parent().prev().prev().children().attr("courseId");
	    $.ajax({
	        type:"POST",
	        url:"/ssm/admin/course/deleteCourse",
	        contentType:"application/x-www-form-urlencoded; charset=utf-8",
	        data:course,
	        dataType:"json",
	        success:function (result){
	            swal(result.msg);
	            $("button").click(function (){
	                location.reload();
	            });
	        },
	        error:function (){
	            alert("更新失败");
	        }
	    });
    })
});